<?php

namespace common\models\invoice;

use Yii;
use yii\behaviors\TimestampBehavior;
/**
 * This is the model class for table "invoice".
 *
 * @property integer $id
 * @property integer $oid
 * @property string $money
 * @property string $title
 * @property string $invoicesn
 * @property integer $invotetime
 * @property string $invotecate
 * @property string $invoterecip
 * @property string $invoteaddress
 * @property string $invotecode
 * @property string $invotephone
 * @property string $invotewuliu
 * @property string $invotewunum
 * @property integer $status
 * @property integer $created_at
 * @property integer $updated_at
 */
class Invoice extends \yii\db\ActiveRecord
{
    const STATUS_DELETED = -1; //未申请
    const STATUS_ACTIVE = 1; //处理中
    const STATUS_SUCCESS = 20; //已开出
    private $_statusLabel;
    public function behaviors()
    {
        return [
            [
                'class' => TimestampBehavior::className(),
            ],
        ];
    }
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'invoice';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['oid', 'invotetime'], 'integer'],

            [['money', 'title', 'invoicesn', 'invotecate', 'invoterecip', 'invoteaddress', 'invotecode', 'invotephone', 'invotewuliu', 'invotewunum'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'oid' => Yii::t('app', '订单id'),
            'money' => Yii::t('app', '发票金额'),
            'title' => Yii::t('app', '发票抬头'),
            'invoicesn' => Yii::t('app', '发票编号'),
            'invotetime' => Yii::t('app', '申请时间'),
            'invotecate' => Yii::t('app', '发票类型'),
            'invoterecip' => Yii::t('app', '发票收件人'),
            'invoteaddress' => Yii::t('app', '收取地址'),
            'invotecode' => Yii::t('app', '邮编'),
            'invotephone' => Yii::t('app', '电话'),
            'invotewuliu' => Yii::t('app', '物流公司'),
            'invotewunum' => Yii::t('app', '快递编号'),
            'status' => Yii::t('app', '状态'),
            'created_at' => Yii::t('app', '创建时间'),
            'updated_at' => Yii::t('app', '更新时间'),
        ];
    }
     /**
     * @inheritdoc
     */
    public function getStatusLabel()
    {
        if ($this->_statusLabel === null) {
            $statuses = self::getArrayStatus();
            $this->_statusLabel = array_key_exists($this->status,self::getArrayStatus()) ? $statuses[$this->status] : '无';
        }
        return $this->_statusLabel;
    }
    /**
     * @inheritdoc
     */
    public static function getArrayStatus()
    {
        return [
            self::STATUS_SUCCESS => Yii::t('app', '已开出'),
            self::STATUS_ACTIVE => Yii::t('app', '处理中'),
            self::STATUS_DELETED => Yii::t('app', '未申请'),

        ];
    }
}
